﻿#include "FITKAbaSurfaceLabel.h"
#include "FITKAbaMeshPartVTK.h"
#include "FITK_Kernel/FITKCore/FITKEnumTransformer.hpp"

//********* FITKAbaSurfaceLabel::GetFaceVtkType调用，处理不同单元类型************************
int GetFaceVtkType_S3(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index);
int GetFaceVtkType_S4(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index);
int GetFaceVtkType_C3D4(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index);
int GetFaceVtkType_C3D6(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index);
int GetFaceVtkType_C3D8(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index);
int GetFaceVtkType_C3D10(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index);
int GetFaceVtkType_R3D4(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index);
//*******************************************************************************************
//********* FITKAbaSurfaceLabel::GetFaceLabel调用，处理不同单元类型************************
Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_S3(const int &index);
Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_S4(const int &index);
Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_C3D4(const int &index);
Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_C3D6(const int &index);
Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_C3D8(const int &index);
Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_C3D10(const int &index);
Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_R3D4(const int &index);
//********************************************************************************************

namespace Interface
{

    int FITKAbaSurfaceLabel::GetFaceVtkType(int abaEleType, AbaSurfLabel label, int &index)
    {
        FITKAbaMeshPartVTK::AbaEleType abaEleTpE = (FITKAbaMeshPartVTK::AbaEleType) abaEleType;

        switch (abaEleTpE)
        {
        case FITKAbaMeshPartVTK::AbaEleNone: break;
        case FITKAbaMeshPartVTK::B31: break;
        case FITKAbaMeshPartVTK::B32: break;
        case FITKAbaMeshPartVTK::T3D2: break;
        case FITKAbaMeshPartVTK::T3D3: break;
        case FITKAbaMeshPartVTK::S3:
        case FITKAbaMeshPartVTK::CPS3:
            return GetFaceVtkType_S3(label, index);
        case FITKAbaMeshPartVTK::S4:
        case FITKAbaMeshPartVTK::S4R:
            return GetFaceVtkType_S4(label, index);
        case FITKAbaMeshPartVTK::S8: break;
        case FITKAbaMeshPartVTK::C3D4:
            return GetFaceVtkType_C3D4(label, index);
        case FITKAbaMeshPartVTK::C3D6:
            return GetFaceVtkType_C3D6(label, index);
        case FITKAbaMeshPartVTK::C3D8:
        case FITKAbaMeshPartVTK::C3D8I:
        case FITKAbaMeshPartVTK::C3D8R:
            return GetFaceVtkType_C3D8(label, index);
        case FITKAbaMeshPartVTK::C3D10:
        case FITKAbaMeshPartVTK::C3D10M:
            return GetFaceVtkType_C3D10(label, index);
        case FITKAbaMeshPartVTK::R3D4:
            return GetFaceVtkType_R3D4(label, index);
        default: return -1;
        }

        return -1;
    }

    FITKAbaSurfaceLabel::AbaSurfLabel FITKAbaSurfaceLabel::GetFaceLabel(int abaEleType, int index, QString &textLabel)
    {
        FITKAbaMeshPartVTK::AbaEleType abaEleTpE = (FITKAbaMeshPartVTK::AbaEleType) abaEleType;
        FITKAbaSurfaceLabel::AbaSurfLabel labelEnum = Empty;

        switch (abaEleTpE)
        {
        case FITKAbaMeshPartVTK::AbaEleNone: break;
        case FITKAbaMeshPartVTK::B31: break;
        case FITKAbaMeshPartVTK::B32: break;
        case FITKAbaMeshPartVTK::T3D2: break;
        case FITKAbaMeshPartVTK::T3D3: break;
        case FITKAbaMeshPartVTK::S3:
        case FITKAbaMeshPartVTK::CPS3:
            labelEnum = GetFaceLabel_S3(index); break;
        case FITKAbaMeshPartVTK::S4:
        case FITKAbaMeshPartVTK::S4R:
            labelEnum = GetFaceLabel_S4(index); break;
        case FITKAbaMeshPartVTK::S8: break;
        case FITKAbaMeshPartVTK::C3D4:
            labelEnum = GetFaceLabel_C3D4(index); break;
        case FITKAbaMeshPartVTK::C3D6:
            labelEnum = GetFaceLabel_C3D6(index); break;
        case FITKAbaMeshPartVTK::C3D8:
        case FITKAbaMeshPartVTK::C3D8I:
        case FITKAbaMeshPartVTK::C3D8R:
            labelEnum = GetFaceLabel_C3D8(index); break;
        case FITKAbaMeshPartVTK::C3D10:
        case FITKAbaMeshPartVTK::C3D10M:
            labelEnum = GetFaceLabel_C3D10(index); break;
        case FITKAbaMeshPartVTK::R3D4:
            labelEnum = GetFaceLabel_R3D4(index); break;
        default: break;;
        }
        if (labelEnum == Empty)return labelEnum;

        Core::FITKEnumTransfer<AbaSurfLabel> sLabTrans;
        bool ok = false;
        textLabel = sLabTrans.toStrting(labelEnum,ok);

        return labelEnum;
    }
}



int GetFaceVtkType_S3(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index)
{
    switch (label)
    {
    case Interface::FITKAbaSurfaceLabel::E1:
        index = 2; return 3; //VTKCellType::VTK_LINE
    case Interface::FITKAbaSurfaceLabel::E2:
        index = 3; return 3; //VTKCellType::VTK_LINE
    case Interface::FITKAbaSurfaceLabel::E3:
        index = 4; return 3; //VTKCellType::VTK_LINE
    case Interface::FITKAbaSurfaceLabel::SPOS:
        index = 0; return 5; //VTKCellType::VTK_TRIANGLE
    case Interface::FITKAbaSurfaceLabel::SNEG:
        index = 1; return 5; // VTKCellType::VTK_TRIANGLE
    default:  break;
    }
    return -1;
}

int GetFaceVtkType_S4(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index)
{
    switch (label)
    {
    case Interface::FITKAbaSurfaceLabel::E1:
        index = 2; return 3; //VTKCellType::VTK_LINE
    case Interface::FITKAbaSurfaceLabel::E2:
        index = 3; return 3; //VTKCellType::VTK_LINE
    case Interface::FITKAbaSurfaceLabel::E3:
        index = 4; return 3; //VTKCellType::VTK_LINE
    case Interface::FITKAbaSurfaceLabel::E4:
        index = 5; return 3; //VTKCellType::VTK_LINE
    case Interface::FITKAbaSurfaceLabel::SPOS:
        index = 0; return 9; //VTKCellType::VTK_QUAD
    case Interface::FITKAbaSurfaceLabel::SNEG:
        index = 1; return 9; // VTKCellType::VTK_QUAD
    default:  break;
    }
    return -1;
}

int GetFaceVtkType_C3D4(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index)
{
    switch (label)
    {
    case Interface::FITKAbaSurfaceLabel::S1:
        index = 0;  return 5; // VTKCellType::VTK_TRIANGLE
    case Interface::FITKAbaSurfaceLabel::S2:
        index = 1;  return 5; // VTKCellType::VTK_TRIANGLE
    case Interface::FITKAbaSurfaceLabel::S3:
        index = 2;  return 5; // VTKCellType::VTK_TRIANGLE
    case Interface::FITKAbaSurfaceLabel::S4:
        index = 3;  return 5; // VTKCellType::VTK_TRIANGLE
    default:  break;
    }
    return -1;
}

int GetFaceVtkType_C3D6(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index)
{
    switch (label)
    {
    case Interface::FITKAbaSurfaceLabel::S1:
        index = 0;  return 5; // VTKCellType::VTK_TRIANGLE
    case Interface::FITKAbaSurfaceLabel::S2:
        index = 1;  return 5; // VTKCellType::VTK_TRIANGLE
    case Interface::FITKAbaSurfaceLabel::S3:
        index = 2;  return 9; // VTKCellType::VTK_QUAD
    case Interface::FITKAbaSurfaceLabel::S4:
        index = 3;  return 9; // VTKCellType::VTK_QUAD
    case Interface::FITKAbaSurfaceLabel::S5:
        index = 4;  return 9; // VTKCellType::VTK_QUAD
    default:  break;
    }
    return -1;
}
int GetFaceVtkType_C3D8(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index)
{
    switch (label)
    {
    case Interface::FITKAbaSurfaceLabel::S1:
        index = 0;  return 9; // VTKCellType::VTK_QUAD
    case Interface::FITKAbaSurfaceLabel::S2:
        index = 1;  return 9; // VTKCellType::VTK_QUAD
    case Interface::FITKAbaSurfaceLabel::S3:
        index = 2;  return 9; // VTKCellType::VTK_QUAD
    case Interface::FITKAbaSurfaceLabel::S4:
        index = 3;  return 9; // VTKCellType::VTK_QUAD
    case Interface::FITKAbaSurfaceLabel::S5:
        index = 4;  return 9; // VTKCellType::VTK_QUAD
    case Interface::FITKAbaSurfaceLabel::S6:
        index = 5;  return 9; // VTKCellType::VTK_QUAD
    default:  break;
    }
    return -1;
}
int GetFaceVtkType_C3D10(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index)
{
    switch (label)
    {
    case Interface::FITKAbaSurfaceLabel::S1:
        index = 0;  return 22; // VTKCellType::VTK_QUADRATIC_TRIANGLE
    case Interface::FITKAbaSurfaceLabel::S2:
        index = 1;  return 22; // VTKCellType::VTK_QUADRATIC_TRIANGLE
    case Interface::FITKAbaSurfaceLabel::S3:
        index = 2;  return 22; // VTKCellType::VTK_QUADRATIC_TRIANGLE
    case Interface::FITKAbaSurfaceLabel::S4:
        index = 3;  return 22; // VTKCellType::VTK_QUADRATIC_TRIANGLE
    default:  break;
    }
    return -1;
}

int GetFaceVtkType_R3D4(Interface::FITKAbaSurfaceLabel::AbaSurfLabel label, int &index)
{
    return GetFaceVtkType_S4(label, index);
}





/**
 * 根据给定的索引获取对应的面标签。
 *
 * @param index 面标签的索引，对应不同的面标识。
 * @return 返回一个AbaSurfLabel枚举类型的值，表示特定的面标签。
 */
Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_S3(const int &index)
{
    // 根据索引值返回对应的面标签
    switch (index)
    {
    case 0: return Interface::FITKAbaSurfaceLabel::SPOS;
    case 1: return Interface::FITKAbaSurfaceLabel::SNEG;
    case 2: return Interface::FITKAbaSurfaceLabel::E1;
    case 3: return Interface::FITKAbaSurfaceLabel::E2;
    case 4: return Interface::FITKAbaSurfaceLabel::E3;
    default: return Interface::FITKAbaSurfaceLabel::Empty;
    }
}

/**
 * 根据给定的索引获取对应的AbaSurfLabel枚举值。
 *
 * @param index 表示要获取的标签的索引，索引值对应于具体的AbaSurfLabel枚举项。
 * @return 返回Interface::FITKAbaSurfaceLabel::AbaSurfLabel类型的枚举值，
 *         根据索引选择对应的枚举项返回，如果索引无效，则返回Empty。
 */
Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_S4(const int &index)
{
    // 使用switch语句根据index的值返回相应的枚举类型
    switch (index)
    {
    case 0: return Interface::FITKAbaSurfaceLabel::SPOS;
    case 1: return Interface::FITKAbaSurfaceLabel::SNEG;
    case 2: return Interface::FITKAbaSurfaceLabel::E1;
    case 3: return Interface::FITKAbaSurfaceLabel::E2;
    case 4: return Interface::FITKAbaSurfaceLabel::E3;
    case 5: return Interface::FITKAbaSurfaceLabel::E4;
    default: return Interface::FITKAbaSurfaceLabel::Empty;
    }
}


/**
 * 根据给定的索引获取对应的面标签。
 *
 * @param index 面标签的索引，必须是0到3之间的整数。
 * @return 返回对应的面标签，如果索引无效，则返回空标签。
 */
Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_C3D4(const int &index)
{
    // 根据索引返回对应的面标签
    switch (index)
    {
    case 0: return Interface::FITKAbaSurfaceLabel::S1;
    case 1: return Interface::FITKAbaSurfaceLabel::S2;
    case 2: return Interface::FITKAbaSurfaceLabel::S3;
    case 3: return Interface::FITKAbaSurfaceLabel::S4;
    default: return Interface::FITKAbaSurfaceLabel::Empty;
    }
}


/**
 * 根据给定的索引获取对应的面标签。
 *
 * @param index 面标签的索引，对应不同的面。
 * @return 返回一个AbaSurfLabel枚举类型的值，表示特定的面标签。
 */
Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_C3D6(const int &index)
{
    // 根据索引返回对应的面标签
    switch (index)
    {
    case 0: return Interface::FITKAbaSurfaceLabel::S1;
    case 1: return Interface::FITKAbaSurfaceLabel::S2;
    case 2: return Interface::FITKAbaSurfaceLabel::S3;
    case 3: return Interface::FITKAbaSurfaceLabel::S4;
    case 4: return Interface::FITKAbaSurfaceLabel::S5;
    default: return Interface::FITKAbaSurfaceLabel::Empty;
    }
}


/**
 * 根据给定的索引获取对应的AbaSurfLabel枚举值。
 *
 * @param index 表示面标签的索引，取值范围为0到5。
 * @return 返回Interface::FITKAbaSurfaceLabel::AbaSurfLabel类型的枚举值。
 *         如果索引不在0到5的范围内，则返回Interface::FITKAbaSurfaceLabel::Empty。
 */
Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_C3D8(const int &index)
{
    // 使用switch语句根据索引返回相应的面标签枚举值
    switch (index)
    {
    case 0: return Interface::FITKAbaSurfaceLabel::S1;
    case 1: return Interface::FITKAbaSurfaceLabel::S2;
    case 2: return Interface::FITKAbaSurfaceLabel::S3;
    case 3: return Interface::FITKAbaSurfaceLabel::S4;
    case 4: return Interface::FITKAbaSurfaceLabel::S5;
    case 5: return Interface::FITKAbaSurfaceLabel::S6;
    default: return Interface::FITKAbaSurfaceLabel::Empty;
    }
}



/**
 * 根据给定的索引获取对应的面标签。
 *
 * @param index 面标签的索引，对应不同的面。
 * @return 返回Interface::FITKAbaSurfaceLabel::AbaSurfLabel类型的面标签，
 *         如果索引无效，则返回Empty标签。
 */
Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_C3D10(const int &index)
{
    // 根据索引返回对应的面标签
    switch (index)
    {
    case 0: return Interface::FITKAbaSurfaceLabel::S1;
    case 1: return Interface::FITKAbaSurfaceLabel::S2;
    case 2: return Interface::FITKAbaSurfaceLabel::S3;
    case 3: return Interface::FITKAbaSurfaceLabel::S4;
    default: return Interface::FITKAbaSurfaceLabel::Empty;
    }
}


Interface::FITKAbaSurfaceLabel::AbaSurfLabel GetFaceLabel_R3D4(const int &index)
{
    return GetFaceLabel_S4(index);
}

